from django.db import models

# Create your models here.

class NavCategory(models.Model):
    """导航栏课程分类(适配原型图结构)"""
    name = models.CharField('分类名称', max_length=10, unique=True)  # 如"免费课"
    display_name = models.CharField('显示名称', max_length=20)      # 如"零基础免费课"
    weight = models.SmallIntegerField('排序权重', default=0)      # 控制导航顺序
    is_active = models.BooleanField('启用状态', default=True)     # 是否显示
    theme_color = models.CharField('主题色值', max_length=7, default='#1890FF')  # 导航标签颜色
    
    # 动态字段（适配原型图需求）
    show_countdown = models.BooleanField('显示倒计时', default=False)  # 学位课需要倒计时
    external_link = models.URLField('外链地址', blank=True)           # 如"老男孩教育"跳转
    
    class Meta:
        verbose_name = '导航分类'
        verbose_name_plural = verbose_name
        ordering = ['weight']  # 按权重自动排序

    def __str__(self):
        return f"{self.name}({self.display_name})"

class Banner(models.Model):
    """轮播图广告模型"""
    title = models.CharField('广告标题', max_length=100)
    link = models.URLField('广告链接', max_length=200)
    image = models.ImageField('广告图片', upload_to='banner/')
    note = models.CharField('备注信息', max_length=200, blank=True, null=True)
    is_show = models.BooleanField('是否显示', default=True)
    weight = models.SmallIntegerField('排序权重', default=0)
    is_deleted = models.BooleanField('是否删除', default=False)
    created_time = models.DateTimeField('创建时间', auto_now_add=True)
    updated_time = models.DateTimeField('更新时间', auto_now=True)

    class Meta:
        verbose_name = '轮播图广告'
        verbose_name_plural = verbose_name
        ordering = ['-weight', '-created_time']  # 按权重降序、创建时间降序排序

    def __str__(self):
        return self.title

class CourseCategory(models.Model):
    """课程分类模型"""
    category_name = models.CharField(max_length=255, verbose_name="分类名称")
    parent = models.ForeignKey('self', null=True, blank=True, on_delete=models.CASCADE, verbose_name="父分类")
    level = models.IntegerField(verbose_name="分类级别")
    description = models.TextField(null=True, blank=True, verbose_name="分类描述")
    created_at = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    updated_at = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'course_categories'
        verbose_name = "课程分类"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.category_name
